package com.springmvc.demo.controller;


import com.springmvc.demo.anntation.User;
import com.springmvc.demo.pojo.MyBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class TestController {

	@RequestMapping("/test1")
	public String sayHello(Integer age, String name) {
		ModelAndView mav = new ModelAndView();
		MyBean bean = new MyBean(age, name);
		mav.addObject("myBean", bean);
		mav.setViewName("sayHello");
		System.out.println(bean.toString());
		return "/static/jsp/sayHello.jsp";
	}

	@RequestMapping("/test2")
	@ResponseBody
	public String test1( @User String aaa) {
		ModelAndView mav = new ModelAndView();
		MyBean bean = new MyBean(1, "name");
		mav.addObject("myBean", bean);
		mav.setViewName("sayHello");
		System.out.println(bean.toString());
		System.out.println(aaa);
		return "mav";
	}

	@RequestMapping("/test3")
	@ResponseBody
	public String test3(MyBean bean) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("myBean", bean);
		mav.setViewName("sayHello");
		System.out.println(bean.toString());
		return "mav";
	}

	@RequestMapping("/test4")
	@ResponseBody
	public String test4(@RequestBody MyBean bean) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("myBean", bean);
		mav.setViewName("sayHello");
		System.out.println(bean.toString());
		return "mav";
	}
}
